package com.yuufa.test.node;

import com.yuufa.node.Node;
import com.yuufa.util.Tool;

public class Main {

    public static void main(String[] args) {
        
        int[] s = Tool.random(7);
        
        Node head = new Node(-1);
        Node ptr = head;
        
        for(int i=0;i<s.length;i++) {
            ptr.setNode(new Node(s[i]));
            ptr = ptr.getNode();
        }
        
        head = head.getNode();
        ptr = head;
        output(head);
        
        head = reverse(head);
        output(head);
    }
    
    public static Node reverse(Node head) {
        
        Node s = null;
        Node r = s;
        
        while(head != null) {
            s = head; head = head.getNode(); s.setNode(r); r = s;
        }
        
        return r;
    }

    public static void output(Node head) {
        
        while(head != null) {
            System.out.print(head.getData() + "->");
            head = head.getNode();
        }
        
        System.out.println();
    }
}
